package com.wyman.aop.framework.adapter;

import com.wyman.aop.MethodBeforeAdvice;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * @Author 李伟民
 * @Description
 * @DateTime 2024/12/29 00:15
 */
//是写好的 不需要用户实现 只需要配置文件中注入容器就可以使用
// 目的是 包装真正的切面功能(advice 这是用户需要实现的) 就可以通过这个类实现在方法执行前调用 关键是定向实现在方法执行前

public class MethodBeforeAdviceInterceptor implements MethodInterceptor {


    private MethodBeforeAdvice advice;

    public MethodBeforeAdviceInterceptor(){

    }

    public MethodBeforeAdviceInterceptor(MethodBeforeAdvice advice){
        this.advice = advice;

    }

    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        this.advice.before(methodInvocation.getMethod(),methodInvocation.getArguments(),methodInvocation.getThis());
        return methodInvocation.proceed();
    }

    public void setAdvice(MethodBeforeAdvice advice) {
        this.advice = advice;
    }
}
